//
//  ViewController.m
//  mobotest
//
//  Created by lmx on 16/6/17.
//  Copyright © 2016年 lmx. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
 //   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSubtitle:) name:@"MoboPlayerShowSubtitleDuration" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)player:(id)sender {

    NSBundle *bundle  = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"魔兽" ofType:@"rmvb"];
//    NSString *path = [bundle pathForResource:@"1001-多音轨01-[奥黛丽·赫本系列01：罗马假日].Roman.Holiday.1953.DVDRiP.X264.2Audio.AAC.HALFCD-NORM.Christian" ofType:@"mkv"];
//    NSString *path = [bundle pathForResource:@"1001-多音轨01-[奥黛丽·赫本系列01：罗马假日].Roman.Holiday.1953.DVDRiP.X264.2Audio.AAC.HALFCD-NORM.Christian" ofType:@"mkv"];
    _vc  = [[MoboViewController alloc]init];
//    _vd =[MoboThumbnail MoboThumbnailonce] ;
//    int ret=   [_vd cmp_save_video_shot:path  gen_time:0 gen_width:0 gen_height:0];
    

    //    [_vc softMovieViewControllerWithContentURL:url parameters:parameters];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
//    NSString *path =@"rtmp://221.2.201.187/flv/mp4:n2014/ys/kc61/kj142/fc/xrfx01.mp4";
   [_vc softMovieViewControllerWithContentPath:path parameters:parameters];
//    NSLog(@"%@", path);
 // [_vc hardMovieViewControllerWithContentPath:path parameters:parameters];
    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(runTimer) userInfo:nil repeats:YES ];
//    [self presentViewController:_vc animated:YES completion:nil];
    _vc.view.frame = self.view.frame;
    [self.view addSubview:_vc.view];
    [self addChildViewController:_vc];

  
//   self.view.transform = CGAffineTransformScale(sel.view.transform, -1.0, 1.0);
  //  NSDictionary * info = [_vc.moboPlayer getStreamNSinfo];
   // NSLog(@"about info :%@ info.count:%lu",info,(unsigned long)info.count);
}

//- (NSString *)replaceUnicode:(NSString *)unicodeStr
//{
//    NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
//    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
//    NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
//    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
//    NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData
//                                                           mutabilityOption:NSPropertyListImmutable
//                                                                     format:NULL
//                                                           errorDescription:NULL];
//    
//    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
//}

- (void)runTimer
{

    
    
    
    static  int   num = 0;
//    [_vc.moboPlayer  setMoboPlayer_speed:num];
    
    
    //  NSLog(@"===================  streaminfo:%@",[_vc.moboPlayer getStreamNSinfo]);
   // NSLog(@"num : %d",num);
    
    num++;
    if (num >2) {
        num = 0;
    }
    
    
    
    
//    NSArray * a =  [_vc.moboPlayer GetSubtitleNSArray];
//    NSLog(@" this subtitle naarray:%@",a);
//    
//    static int num = 0;
//    NSBundle *bundle  = [NSBundle mainBundle];
//    NSString *path = [bundle pathForResource:@"1101-字幕01-[YYDM-11FANS][CLANNAD][BDrip][24][X264_AAC][1280X720]" ofType:@"ass"];
//    if(num == 0)
//    if( [_vc.moboPlayer AddSubtitleFile:path])
//        NSLog(@"打开字幕文件成功");
//    else
//        NSLog(@"打开字幕文件失败");
//    
//    
//    if (num == 1) {
//       NSArray *arr1=[NSArray arrayWithObject:@"0"];
//        [_vc.moboPlayer setSelectedSubtitleStream:arr1];
//    }
//    
//    num +=1;
//    if (num >2) {
//        NSInteger num2  = [_vc.moboPlayer getSubtitleCount];
//        NSLog(@" the subtile count :%ld",(long)num2);
//    }
//    num += 1;
//    if(num >4)
//    num =0;
    
        
    
//    NSInteger audionum = [_vc.moboPlayer getAudioCount];
//    NSLog(@"this  audiostreamcount : %ld",(long)audionum);
//    NSInteger subtitlenum = [_vc.moboPlayer getSubtitleCount];
//    NSLog(@"this  subtitlestreamcount : %ld",(long)subtitlenum);
//    
//    NSArray * array = [_vc.moboPlayer AudioStreamNSArray];
//    NSLog(@"%@",array);
  //  UIImage * info = [_vc.moboPlayer SaveScreenShot:0 height:0];
//    if(info == NULL)
//    {
//        NSLog(@"asdasdasdas=======================");
//    }
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.backgroundColor = [UIColor whiteColor];
    imageView.image = [_vc.moboPlayer SaveScreenShot:0 height:0];;
    imageView.frame = CGRectMake(0, 0, 200, 200);
    [_vc.view addSubview:imageView];
//    [self loadImageFinished:info];
//    NSDictionary * info = [_vc.moboPlayer getStreamNSinfo];
//    NSString * subtitle1 = [info objectForKey:@"subtitles"];
    //NSLog(@"%@", subtitle1);
//    NSLog(@"about info :%@ subtitle:%@",info,[self replaceUnicode :subtitle1]);
//    NSString *subtitlestring = [_vc.moboPlayer getSubtitleString];
//    if(subtitlestring)
//    NSLog(@"subtitle: %@", subtitlestring);
//    if ([_vc.moboPlayer hasSubtitle]) {
//        NSLog(@"has subtitle");
//    }
//    [_vc.moboPlayer  seekToTime: 300];
}

- (void)loadImageFinished:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    
    NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
}


-(void) showSubtitle:(NSNotification *)noti{
  //  NSLog([noti.userInfo objectForKey:@"showsubtitlelable"]);
}

//- (void) ShowSubtitleLable:(NSString*)nsstring
//{
//    NSLog(nsstring);
//}

@end
